setwd("E:/5hmc_file/2_5hmc_yjp_bam/ASM/")
file=read.csv("20201112做汇总表/all.FDR.sig.at.least.one.csv",head=T)
file[file=="normal_up_tumor_up"]="normal_up-tumor_up"
file[file=="normal_down_tumor_down"]="normal_down-tumor_down"

file$upup.num=rowSums(file[,1:121]=="normal_up-tumor_up",na.rm = T)
file$downdown.num=rowSums(file[,1:121]=="normal_down-tumor_down",na.rm = T)

file$upup.DC.num=rowSums(file[,1:57]=="normal_up-tumor_up",na.rm = T)
file$upup.CC.num=rowSums(file[,58:89]=="normal_up-tumor_up",na.rm = T)
file$upup.HC.num=rowSums(file[,90:121]=="normal_up-tumor_up",na.rm = T)
file$downdown.DC.num=rowSums(file[,1:57]=="normal_down-tumor_down",na.rm = T)
file$downdown.CC.num=rowSums(file[,58:89]=="normal_down-tumor_down",na.rm = T)
file$downdown.HC.num=rowSums(file[,90:121]=="normal_down-tumor_down",na.rm = T)


file1=file[file$upup.num>1|file$downdown.num>1,]
table(file$upup.HC.num>1|file$downdown.HC.num>1)
table(file$downdown.HC.num>1)

direction1=c("normal_up-tumor_nosig","normal_down-tumor_nosig","normal_nosig-tumor_up","normal_down-tumor_up","normal_up-tumor_down","normal_nosig-tumor_down","one_is_down","one_is_up","onedown_oneup")

file$diff.direction.num1=rowSums(file[,1:121]=="normal_up-tumor_nosig"|file[,1:121]=="one_is_up"|file[,1:121]=="normal_nosig-tumor_up",na.rm = T)
file$diff.direction.num2=rowSums(file[,1:121]=="normal_down-tumor_nosig"|file[,1:121]=="one_is_down"|file[,1:121]=="normal_nosig-tumor_down",na.rm = T)
file$diff.direction.num3=rowSums(file[,1:121]=="normal_up-tumor_down"|file[,1:121]=="normal_down-tumor_up"|file[,1:121]=="onedown_oneup",na.rm = T)

table(file$diff.direction.num1>1|file$diff.direction.num2>1|file$diff.direction.num3>1)
table(file$diff.direction.num3>1)

file$diff.direction.DC.num1=rowSums(file[,1:57]=="normal_up-tumor_nosig"|file[,1:57]=="one_is_up"|file[,1:57]=="normal_nosig-tumor_up",na.rm = T)
file$diff.direction.DC.num2=rowSums(file[,1:57]=="normal_down-tumor_nosig"|file[,1:57]=="one_is_down"|file[,1:57]=="normal_nosig-tumor_down",na.rm = T)
file$diff.direction.DC.num3=rowSums(file[,1:57]=="normal_up-tumor_down"|file[,1:57]=="normal_down-tumor_up"|file[,1:57]=="onedown_oneup",na.rm = T)
table(file$diff.direction.DC.num1>1|file$diff.direction.DC.num2>1|file$diff.direction.DC.num3>1)

file$diff.direction.CC.num1=rowSums(file[,58:89]=="normal_up-tumor_nosig"|file[,58:89]=="one_is_up"|file[,58:89]=="normal_nosig-tumor_up",na.rm = T)
file$diff.direction.CC.num2=rowSums(file[,58:89]=="normal_down-tumor_nosig"|file[,58:89]=="one_is_down"|file[,58:89]=="normal_nosig-tumor_down",na.rm = T)
file$diff.direction.CC.num3=rowSums(file[,58:89]=="normal_up-tumor_down"|file[,58:89]=="normal_down-tumor_up"|file[,58:89]=="onedown_oneup",na.rm = T)
table(file$diff.direction.CC.num1>1|file$diff.direction.CC.num2>1|file$diff.direction.CC.num3>1)
table(file$diff.direction.CC.num3>1)

file$diff.direction.HC.num1=rowSums(file[,90:121]=="normal_up-tumor_nosig"|file[,90:121]=="one_is_up"|file[,90:121]=="normal_nosig-tumor_up",na.rm = T)
file$diff.direction.HC.num2=rowSums(file[,90:121]=="normal_down-tumor_nosig"|file[,90:121]=="one_is_down"|file[,90:121]=="normal_nosig-tumor_down",na.rm = T)
file$diff.direction.HC.num3=rowSums(file[,90:121]=="normal_up-tumor_down"|file[,90:121]=="normal_down-tumor_up"|file[,90:121]=="onedown_oneup",na.rm = T)
table(file$diff.direction.HC.num1>1|file$diff.direction.HC.num2>1|file$diff.direction.HC.num3>1)
table(file$diff.direction.HC.num3>1)
write.csv(file,"20201112做汇总表/all.FDR.sig.at.least.one.add.direction.same.diff.csv",quote=F,row.names = F)
